﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZK.Common
{

    /// <summary>
    /// 记录日志(建议自己动手创建文件夹)
    /// </summary>
    /// <param name="msg"></param>
    public class SimpleLog
    {
        public static void WriteLog(string msg)
        {
            //string path = @"C:\log.txt";
            //该日志文件会存在windows服务程序目录下
            string pathOfTime = DateTime.Now.ToString("yyyy-MM-dd");
            string path = AppDomain.CurrentDomain.BaseDirectory + "\\ReaderLog\\" + pathOfTime + ".txt";
            FileInfo file = new FileInfo(path);
            if (!file.Exists)
            {
                FileStream fs;
                fs = File.Create(path);
                fs.Close();
            }

            using (FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write))
            {
                using (StreamWriter sw = new StreamWriter(fs))
                {
                    sw.WriteLine(DateTime.Now.ToString() + "   " + msg);
                }
            }
        }
    }
}
